package lx6;

import java.util.Objects;
import java.util.Random;

public class Box extends Thread{
    private static final int[] a = {10,5,20,100,200,500,800,2,80,300,700};
    private static Random R = new Random();
    private static int cnt = 1;
    private static final Object lock = new Object();
    @Override
    public void run() {
        while(true){
            synchronized (lock){
                if(cnt ++ >= 200)break;
                int idx = R.nextInt(a.length);
                System.out.println(cnt + "  " + this.getName() + " --> "+a[idx] + "元");
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
